#include "GeometryPass.h"

#include <iostream>

#include "GameNode.h"
#include "Mesh.h"
#include "Material.h"
#include "Transform.h"

#include <gtc/matrix_transform.hpp>



GLuint gGColorBuffer;
GLuint gGNormalBuffer;
GLuint gGeometryFBO;

// ---- TO TEST TO REMOVE! -----

RefPtr<GameNode>	gNode;

RefPtr<Mesh>		gMesh;
RefPtr<Material>	gMat;
glm::mat4			gPersp;
glm::mat4			gTrans;

//--------------- create the FBO and render target

void initGeometryPass()
{
	//glGenFramebuffers(1, &gGeometryFBO);

	glClearColor(1.0f, 0.0f, 0.0f, 1.0f);

	Vertex lVert[3];

	lVert[0].x = -1;
	lVert[0].y = -1;
	lVert[0].z =  0;
	lVert[0].w =  1;
	lVert[1].x = -1;
	lVert[1].y =  1;
	lVert[1].z =  0;
	lVert[1].w =  1;
	lVert[2].x =  1;
	lVert[2].y =  1;
	lVert[2].z =  0;
	lVert[2].w =  1;

	unsigned int pIndice[3] = {0,1,2};

	gMesh = new Mesh(lVert, 3, &pIndice[0], 3);
	gMat = new Material();

	gTrans = glm::translate(gTrans, glm::vec3(0,0,-20));

	gPersp = glm::perspective(60.0f, 800.0f/600.0f, 0.01f, 10000.0f);

	
	gNode = new GameNode();
	gNode->getTransform()->rotateLocalAround(glm::vec3(0, 1, 0), 90);
}


//-------------------------------------------------

void geometryPassSetup()
{
	// ------ set the render target
	gNode->Update();
}

void geometryPassRender()
{
	glm::vec3 lForw = gNode->getTransform()->getForward();
	std::cout<<lForw.x<<";"<<lForw.y<<";"<<lForw.z<<std::endl;

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	gMat->bindShader();
	gMat->bindMatrix("ModelViewProjection", gPersp*gTrans);

	gMesh->bindBuffers();
	gMesh->draw();
}